package com.ruoyi.web.controller.miniapp;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.miniapp.domain.MiniChildInfo;
import com.ruoyi.miniapp.domain.MiniGroupInfo;
import com.ruoyi.miniapp.domain.vo.MiniActivityVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.miniapp.domain.MiniActivity;
import com.ruoyi.miniapp.service.IMiniActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动Controller
 * 
 * @author duantao
 * @date 2025-09-09
 */
@RestController
@RequestMapping("/miniapp/activity")
public class MiniActivityController extends BaseController
{
    @Autowired
    private IMiniActivityService miniActivityService;

    /**
     * 查询活动列表
     */
//    @PreAuthorize("@ss.hasPermi('miniapp:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(MiniActivity miniActivity)
    {
        startPage();
        List<MiniActivityVO> list = miniActivityService.selectMiniActivityList(miniActivity);
        return getDataTable(list);
    }
    /**
     * 查询活动个人报名信息
     */
//    @PreAuthorize("@ss.hasPermi('miniapp:activity:list')")
    @GetMapping(value = "/getSignUpByPerson/{activityId}")
    public TableDataInfo getSignUpByPerson(@PathVariable("activityId") Long activityId)
    {
        startPage();
        List<MiniChildInfo> list = miniActivityService.getSignUpInfoByChildren(activityId);
        return getDataTable(list);
    }
    /**
     * 查询活动个人报名信息
     */
//    @PreAuthorize("@ss.hasPermi('miniapp:activity:list')")
    @GetMapping(value = "/getSignUpByGroup/{activityId}")
    public TableDataInfo getSignUpByGroup(@PathVariable("activityId") Long activityId)
    {
        startPage();
        List<MiniGroupInfo> list = miniActivityService.getSignUpInfoByGroup(activityId);
        return getDataTable(list);
    }

    /**
     * 导出活动报名信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:activity:export')")
    @Log(title = "活动报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSignUpByGroup")
    public void exportSignUpByGroup(HttpServletResponse response, Long activityId)
    {
        List<MiniGroupInfo> signUpInfoByGroup = miniActivityService.getSignUpInfoByGroup(activityId);
        ExcelUtil<MiniGroupInfo> util = new ExcelUtil<>(MiniGroupInfo.class);
        util.exportExcel(response, signUpInfoByGroup, "活动团队报名");
    }
    /**
     * 导出活动报名信息
     */
    @PreAuthorize("@ss.hasPermi('miniapp:activity:export')")
    @Log(title = "活动报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/exportSignUpByPerson")
    public void exportSignUpByPerson(HttpServletResponse response, Long activityId)
    {
        List<MiniChildInfo> signUpInfoByChildren = miniActivityService.getSignUpInfoByChildren(activityId);
        ExcelUtil<MiniChildInfo> util = new ExcelUtil<>(MiniChildInfo.class);
        util.exportExcel(response, signUpInfoByChildren, "活动个人报名");
    }
    /**
     * 导出活动列表
     */
    @PreAuthorize("@ss.hasPermi('miniapp:activity:export')")
    @Log(title = "活动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniActivity miniActivity)
    {
        List<MiniActivityVO> list = miniActivityService.selectMiniActivityList(miniActivity);
        ExcelUtil<MiniActivityVO> util = new ExcelUtil<>(MiniActivityVO.class);
        util.exportExcel(response, list, "活动数据");
    }

    /**
     * 获取活动详细信息
     */
//    @PreAuthorize("@ss.hasPermi('miniapp:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(miniActivityService.selectMiniActivityByActivityId(activityId));
    }

    /**
     * 新增活动
     */
    @PreAuthorize("@ss.hasPermi('miniapp:activity:add')")
    @Log(title = "活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniActivity miniActivity)
    {
        return toAjax(miniActivityService.insertMiniActivity(miniActivity));
    }

    /**
     * 修改活动
     */
    @PreAuthorize("@ss.hasPermi('miniapp:activity:edit')")
    @Log(title = "活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniActivity miniActivity)
    {
        return toAjax(miniActivityService.updateMiniActivity(miniActivity));
    }

    /**
     * 删除活动
     */
    @PreAuthorize("@ss.hasPermi('miniapp:activity:remove')")
    @Log(title = "活动", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(miniActivityService.deleteMiniActivityByActivityIds(activityIds));
    }
}
